Google News
logo
Python Program to Return the value of x to the power of y (x^y)
Here's a Python program that takes two numbers `x` and `y` as input from the user and calculates the value of `x` raised to the power of `y` using the `**` operator:
Program :
x = float(input("Enter a number: "))
y = float(input("Enter another number: "))
result = x ** y
print(f"{x} raised to the power of {y} is {result}")
Output :
Enter a number: 4
Enter another number: 3
4.0 raised to the power of 3.0 is 64.0
In this program, we first take two numbers as input from the user using the `input()` function. We convert the input values to `float` data type using the `float()` function since we want to allow for decimal numbers as well.

Next, we calculate the value of `x` raised to the power of `y` using the `**` operator and assign it to the variable `result`.

Finally, we use the `print()` function to display the result to the user in a human-readable format using f-string formatting.